package learn;

import java.util.ArrayList;
import java.util.List;

class oneFeature{
	public ArrayList <Integer> varList;
	public ArrayList <Integer> valList;
	oneFeature(){
		varList = new ArrayList<Integer>();
		valList = new ArrayList<Integer>();
	}
	oneFeature(ArrayList<Integer> varList, ArrayList<Integer> valList){
		this.varList = new ArrayList<Integer>(varList);
		this.valList = new ArrayList<Integer>(valList);
	}
	
	public static Boolean isListSame(List<Integer> A,List<Integer> B){
		if (A.size() != B.size())
			return false;
		for(Integer i=0;i<A.size();i++){
			if( A.get(i) != B.get(i)){
				return false;
			}
		}		
		return true;
	}
	
	public Boolean isSame(ArrayList<Integer> varList, ArrayList<Integer> valList){
		if(isListSame(varList,this.varList) == false)
			return false;
		if(isListSame(valList,this.valList) == false)
			return false;		
		return true;
	}

	public Boolean isSameVarList(ArrayList<Integer> varList){
		if(isListSame(varList,this.varList) == false)
			return false;				
		return true;
	}
	@Override
	public String toString() {
		return "oneFeature [varList=" + varList + ", valList=" + valList + "]";
	}
}


public class Feature {
	Integer numVarSubset=0;
	Integer fno;
	List <oneFeature> list;
	Double weight;
	Double gWeight;
	Double cntOberserved;
	Double cntExpected;
	int length;
	
	public Feature(){
		numVarSubset = 0;
		fno=0;
		weight = 1.0;
		gWeight = 0.0;
		cntOberserved = cntExpected = 0.0;
		list = new ArrayList<oneFeature>();
	}
	
	public Integer findIndex(ArrayList<Integer> varList, ArrayList<Integer> valList){
		for(Integer i=0;i<numVarSubset;i++){
			if(list.get(i).isSame(varList, valList))
				return i;
		}
		return -1;
	}

	public Integer findIndex(ArrayList<Integer> varList){
		for(Integer i=0;i<numVarSubset;i++){
			if(list.get(i).isSameVarList(varList))
				return i;
		}
		return -1;
	}

	
	public Boolean isSame(ArrayList<Integer> varList, ArrayList<Integer> valList){
		return findIndex(varList,valList)!=-1;
	}

	public Boolean isSameVarList(ArrayList<Integer> varList){
		return findIndex(varList)!=-1;
	}

	public void set(Integer no, ArrayList<Integer> varList, ArrayList<Integer> valList){
		this.fno = no;
		Integer index = findIndex(varList, valList);
		if(index==-1){
			oneFeature one = new oneFeature(varList, valList);
			list.add(one);
			numVarSubset++;
		}
	}
	


	@Override
	public String toString() {
		return "Feature [numVarSubset=" + numVarSubset + ", fno=" + fno
				+ ", list=" + list + ", weight=" + weight + ", gWeight="
				+ gWeight + ", cntOberserved=" + cntOberserved
				+ ", cntExpected=" + cntExpected + "]";
	}

	public Double getScore(ArrayList<Integer> varList, ArrayList<Integer> valList){
		Integer index = findIndex(varList, valList);
		if(index==-1){
			return 0.0;
		}
		return this.weight;
	}

}
